home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / pcl4c60.zip / SPAWN.C < prev    next >
Text File  |  1996-10-20  |  3KB  |  110 lines

  1. /*
  2. **  spawn.c (11/07/95)
  3. **
  4. **  Spawns "DOOR.EXE", and verifies that the PIC and the UART
  5. **  interrupt enable register, UART line control, and UART modem
  6. **  control registers are restored to their state before spawning.
  7. **
  8. **  If you allocate dynamic memory (malloc) in a door program, be
  9. **  sure to free the memory before exiting.
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <process.h>
  15. #include <dos.h>
  16. #include <string.h>
  17. #include <conio.h>
  18. #include "pcl4c.h"
  19.  
  20. #define FALSE 0
  21. #define TRUE !FALSE
  22. #define CTLZ 0x1a
  23.  
  24. /*** Global Variables ***/
  25.  
  26. static int Port = COM1;          /* Port COM1 */
  27. static int BaudCode = Baud2400;  /* baud rate code */
  28. static char RxBuffer[128+16];    /* 128 byte buffer */
  29. static char TxBuffer[128+16];    /* 128 byte buffer */
  30.  
  31. /*** local prototypes */
  32.  
  33. int BaudMatch(char *);
  34. int ErrorCheck(int);
  35.  
  36. /*** main ***/
  37.  
  38. void main(int argc, char *argv[])
  39. {char c;
  40.  int  i, rc;
  41.  char far *Ptr;
  42.  int  Seg;
  43.  if(argc!=2)
  44.    {printf("Usage: SPAWN <port> \n");
  45.     exit(1);
  46.    }
  47.  /* get port number from command line */
  48.  Port = atoi(argv[1]) - 1;
  49.  if((Port<COM1) || (Port>COM20))
  50.      {printf("SPAWN: Port must be COM1 to COM20\n");
  51.       exit(1);
  52.      }
  53.  /* setup 128 byte receive buffer */
  54.  Ptr = (char far *)RxBuffer;
  55.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  56.  SioRxBuf(Port,Seg,Size128);
  57.  /* setup 128 byte transmit buffer */
  58.  Ptr = (char far *)TxBuffer;
  59.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  60.  SioTxBuf(Port,Seg,Size128);
  61.  printf("SPAWN: Starting...\n");
  62.  SioRxBuf(Port,Seg,Size128);
  63.  /* set port parmameters */
  64.  ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
  65.  /* reset the port */
  66.  ErrorCheck( SioReset(Port,BaudCode) );
  67.  /* set DTR and RTS */
  68.  ErrorCheck( SioDTR(Port,'S') );
  69.  ErrorCheck( SioRTS(Port,'S') );
  70.  printf("\nSPAWN: Type '$' to spawn DOOR.EXE\n");
  71.  printf("SPAWN: Type ^Z to exit\n\n");
  72.  /* enter terminal loop */
  73.  while(TRUE)
  74.      {/* was key pressed ? */
  75.       if(kbhit())
  76.           {i = getch();
  77.            if((char)i==CTLZ)
  78.               {/* restore COM port status & exit */
  79.                SioDone(Port);
  80.                printf("SPAWN: Exiting...\n");
  81.                exit(0);
  82.               }
  83.            else if((char)i=='$')
  84.               {/* spawn DOOR.EXE */
  85.                printf("SPAWN: Spawning DOOR [DTR=%d]\n",SioDTR(Port,'R') );
  86.                if(spawnl(P_WAIT,"DOOR.EXE","DOOR",argv[1],NULL)==-1)
  87.                   {printf("SPAWN: Cannot spawn DOOR.EXE\n");
  88.                    SioDone(Port);
  89.                    exit(1);
  90.                   }
  91.                printf("SPAWN: Returned from DOOR [DTR=%d]\n",SioDTR(Port,'R') );
  92.               }
  93.            else SioPutc(Port,(char)i);
  94.           } /* end if */
  95.       /* any incoming over serial port ? */
  96.       i = SioGetc(Port,0);
  97.       if(i>-1) putch((char)i);
  98.      } /* end while */
  99. } /* end main */
  100.  
  101. int ErrorCheck(int Code)
  102. {/* trap PCL error codes */
  103.  if(Code<0)
  104.      {SioError(Code);
  105.       SioDone(Port);
  106.       exit(1);
  107.      }
  108.  return(0);
  109. } /* end ErrorCheck */
  110.